package com.demo.rocketmq.web;

import com.demo.rocketmq.message.MessageProducer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class MessagePage {

  @Autowired
  private MessageProducer messageProducer;

  @GetMapping("/sendEasyMsg")
  public String sendEasyMsg(){
    log.info("接收到 sendEasyMsg 请求");

    try {
      messageProducer.sendTestMessage();
      log.info("处理 sendEasyMsg 请求结束");
    } catch (Exception e){
      log.error("{}",e);
      return "sendEasyMsg Exception";
    }
    return "sendEasyMsg succ";
  }

  @GetMapping("/SendMesageBuilder")
  public String sendMesageBuilder(){
    log.info("接收到 sendMesageBuilder 请求");

    try {
      messageProducer.sendWithMessageBuilder();
      log.info("处理 sendMesageBuilder 请求结束");
    } catch (Exception e){
      log.error("{}",e);
      return "sendMesageBuilder Exception";
    }
    return "sendMesageBuilder succ";
  }

  @GetMapping("/sendBatch")
  public String sendBatch(){
    log.info("接收到 sendBatch 请求");

    try {
      messageProducer.sendBatchMessage();
      log.info("处理 sendBatch 请求结束");
    } catch (Exception e){
      log.error("{}",e);
      return "sendBatch Exception";
    }
    return "sendBatch succ";
  }

  @GetMapping("/sendUserDef")
  public String sendUserDef(){
    log.info("接收到 sendUserDef 请求");

    try {
      messageProducer.sendUserDefineObject();
      log.info("处理 sendUserDef 请求结束");
    } catch (Exception e){
      log.error("{}",e);
      return "sendUserDef Exception";
    }
    return "sendUserDef succ";
  }

  @GetMapping("/sendOrderMessage")
  public String sendOrderMessage(){
    log.info("接收到 sendOrderMessage 请求");

    try {
      messageProducer.sendBatchOrderMessage();
      log.info("处理 sendOrderMessage 请求结束");
    } catch (Exception e){
      log.error("{}",e);
      return "sendOrderMessage Exception";
    }
    return "sendOrderMessage succ";
  }

  @GetMapping("/sendTransactionMessage")
  public String sendTransactionMessage(){
    log.info("接收到 sendTransactionMessage 请求");

    try {
      messageProducer.sendTransactionMessage();
      log.info("处理 sendTransactionMessage 请求结束");
    } catch (Exception e){
      log.error("{}",e);
      return "sendTransactionMessage Exception";
    }
    return "sendTransactionMessage succ";
  }
}
